package cn.com.zpark.servlet_request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @PackageName: cn.com.zpark.servlet_request
 * @ClassName: RequestDemo02
 * @Description:
 * @author: RZS
 * @date: 2021/11/14  15:27
 */
@WebServlet("/rd2.do")
public class RequestDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 获取请求头中的信息
         */
        // 1、获取所有请求头字段的字段名字
        Enumeration<String> names = req.getHeaderNames();
        // 遍历取出值
        while (names.hasMoreElements()) {
            // 获取请求头字段名字
            String name = names.nextElement();
            // 根据请求头字段名字获取对应的值
            String value = req.getHeader(name);

            System.out.println(name+"："+value);
        }

        System.out.println("***************************************");
        System.out.println(req.getContentType());
        System.out.println(req.getContentLength());
        System.out.println(req.getCharacterEncoding());
    }
}
